package com.htc.android.footprints.activity;

import android.app.Dialog;
import android.app.LocalActivityManager;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.text.Editable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.BackgroundColorSpan;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewParent;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.Filter;
import android.widget.FilterQueryProvider;
import android.widget.ImageView;
import android.widget.ResourceCursorAdapter;
import android.widget.SectionIndexer;
import android.widget.TextView;
import android.widget.Toast;
import com.htc.android.footprints.ILocationAgentService;
import com.htc.android.footprints.ILocationAgentService.Stub;
import com.htc.android.footprints.commonui.HtcDialog;
import com.htc.android.footprints.commonui.HtcDialog.ImportDialog;
import com.htc.android.footprints.provider.FootprintManager;
import com.htc.android.footprints.service.LocationAgentService;
import com.htc.android.footprints.utils.FootprintUtils;
import com.htc.android.footprints.utils.PreloadDataRunnable;
import com.htc.android.footprints.utils.PreloadDataRunnable.PreloadListener;
import com.htc.android.footprints.utils.SettingInfo;
import com.htc.android.footprints.utils.StorageUtil;
import com.htc.android.footprints.utils.StorageUtil.OnChangeStorageListener;
import com.htc.android.footprints.utils.camera.FootprintImageManager;
import com.htc.android.footprints.vo.Category;
import com.htc.android.footprints.vo.Footprint;
import com.htc.widget.HtcAbsListView.RecyclerListener;
import com.htc.widget.HtcAdapterView;
import com.htc.widget.HtcAdapterView.OnItemClickListener;
import com.htc.widget.HtcAdapterView.OnItemLongClickListener;
import com.htc.widget.HtcAlertDialog.Builder;
import com.htc.widget.HtcListItemSeparable;
import com.htc.widget.HtcListView;
import com.htc.widget.TabSwitchActivity;
import com.htc.widget.TabSwitchHost;
import com.htc.widget.TabSwitchHost.OnTabChangeSpecialListener;
import com.htc.widget.TabSwitchHost.TabContentFactory;
import com.htc.widget.TabSwitchHost.TabSpec;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class ListModeNewActivity extends TabSwitchActivity
{
  private static final int CONTEXT_MENU = 7;
  private static final int DELETE_FOOTPRINT_DIALOG = 6;
  private static final int FILEPICKER_REQUEST_CODE = 10;
  private static final int FILE_PICKER_NOT_FOUND_DIALOG = 4;
  private static final int FIRST_LAUNCH_DIALOG = 0;
  private static final int HEADER_VIEW_COUNT = 1;
  public static final int IMPORT_CANCEL = 3;
  public static final int IMPORT_NO = 2;
  public static final int IMPORT_YES = 1;
  private static final int MENU_CREATE_NEW_FOOTPRINT = 2;
  private static final int MENU_DELETE = 5;
  private static final int MENU_EXPORT = 3;
  private static final int MENU_IMPORT = 4;
  private static final int MENU_SEARCH = 7;
  private static final int MENU_SETTING = 6;
  private static final int MENU_SHOW_ON_MAP = 0;
  private static final int MENU_SORT = 1;
  private static final int NO_INTERNAL_STORAGE_DIALOG = 1;
  private static final int PHOTO_PICKER_NOT_FOUND_DIALOG = 5;
  public static final String PICK_FOOTPRINT = "pick_footprint";
  private static final int PROGRESS_DIALOG = 2;
  private static final int REQUEST_CHOOSE_PHOTO = 2;
  public static final int REQUEST_EDIT = 400;
  public static final int REQUEST_IMPORT_DIALOG_CODE = 300;
  private static final int SERVICE_BINDED = 2;
  private static final int SERVICE_BINDING = 1;
  private static final int SERVICE_UNBIND = 0;
  private static final int SORT_DATE = 1;
  private static final int SORT_DIALOG = 3;
  private static final int SORT_NAME = 0;
  private static final String TAG = "ListModeActivity";
  private Category curCategory;
  private boolean cursorMayBeDirty = false;
  private FootprintManager dbManager;
  public boolean isApplyAll = false;
  public boolean isCancelImport = false;
  public int isOverwrite = 1;
  public boolean isWaitDialg = false;
  private HtcListView listView;
  private View listmode;
  public ListModeAdapter mAdapter;
  private View mAddNewFootprintView;
  private int mBindState = 0;
  private ServiceConnection mConnection = new ServiceConnection()
  {
    public void onServiceConnected(ComponentName paramComponentName, IBinder paramIBinder)
    {
      Log.i("ListModeActivity", "onServiceConnected");
      ListModeNewActivity.access$2102(ListModeNewActivity.this, 2);
      ListModeNewActivity.this.mService = ILocationAgentService.Stub.asInterface(paramIBinder);
    }

    public void onServiceDisconnected(ComponentName paramComponentName)
    {
      ListModeNewActivity.access$2102(ListModeNewActivity.this, 0);
    }
  };
  private Filter mFilter;
  private boolean mIsPicker = false;
  private boolean mIsPreloadComplete = false;
  private TabSwitchHost mPanelHost;
  private TextView mSearchInput;
  private View mSearchView;
  ILocationAgentService mService = null;
  private StorageUtil mStorageUtil;
  private TextView mTitleView;
  private PreloadDataRunnable preloadRunnable;
  private Footprint selectedFootprint;
  private String sortBy = "create_time desc";
  private int sortMode = 1;
  private File sourceFile;

  // ERROR //
  private void advancedImportKML(File paramFile)
  {
  }

  // ERROR //
  private void advancedImportKMZ(File paramFile)
  {
  }

  private void bindLocationService()
  {
    Log.i("ListModeActivity", "bindLocationService. mBindState = SERVICE_BINDING");
    this.mBindState = 1;
    Intent localIntent = new Intent();
    localIntent.setClass(this, LocationAgentService.class);
    bindService(localIntent, this.mConnection, 1);
  }

  private void doPickPhotoAction(File paramFile)
  {
    Intent localIntent = new Intent();
    localIntent.setAction("com.android.camera.action.CROP");
    localIntent.setDataAndType(Uri.parse("file://" + paramFile.getAbsolutePath()), "image/*");
    localIntent.putExtra("crop", "true");
    localIntent.putExtra("aspectX", 1);
    localIntent.putExtra("aspectY", 1);
    localIntent.putExtra("outputX", 400);
    localIntent.putExtra("outputY", 400);
    localIntent.putExtra("return-data", true);
    try
    {
      startActivityForResult(localIntent, 2);
      return;
    }
    catch (ActivityNotFoundException localActivityNotFoundException)
    {
      while (true)
        showDialog(5);
    }
  }

  private void showSearch(boolean paramBoolean)
  {
    if (paramBoolean)
    {
      this.mSearchView.setVisibility(0);
      this.mSearchInput.requestFocus();
      this.mTitleView.setVisibility(4);
      if ((this.curCategory != null) && (!this.curCategory.equals(Category.getAllCategory().mKeyword)))
        break label99;
      this.mTitleView.setText(getResources().getString(2131361880));
    }
    while (true)
    {
      return;
      this.mSearchInput.setText("");
      this.mSearchView.setVisibility(8);
      this.mTitleView.setVisibility(0);
      break;
      label99: this.mTitleView.setText(this.curCategory.mName);
    }
  }

  private void unbindLocationService()
  {
    if (this.mBindState != 0);
    try
    {
      if (this.mService != null)
        this.mService.shutdownAgent();
      unbindService(this.mConnection);
      this.mService = null;
      this.mBindState = 0;
      return;
    }
    catch (RemoteException localRemoteException)
    {
      while (true)
        localRemoteException.printStackTrace();
    }
  }

  protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    if (paramInt2 != -1);
    while (true)
    {
      return;
      if (paramInt1 == 2)
      {
        Bitmap localBitmap = (Bitmap)paramIntent.getParcelableExtra("data");
        FootprintUtils.importJPG(getApplicationContext(), this.sourceFile, localBitmap, this.curCategory.mKeyword);
        this.sourceFile = null;
      }
      if (paramInt1 == 300)
      {
        this.isApplyAll = paramIntent.getBooleanExtra("isApplyAll", false);
        this.isWaitDialg = paramIntent.getBooleanExtra("isWaitDialog", false);
        this.isOverwrite = paramIntent.getIntExtra("isOverwrite", 1);
        this.isCancelImport = paramIntent.getBooleanExtra("isCancelImport", false);
      }
      if ((paramInt1 != 10) || (paramIntent == null))
        continue;
      this.sourceFile = null;
      String[] arrayOfString = paramIntent.getStringArrayExtra("output");
      if ((arrayOfString == null) || (arrayOfString.length == 0))
        continue;
      this.sourceFile = new File(arrayOfString[0]);
      showDialog(2);
      new Thread()
      {
        public void run()
        {
          if (ListModeNewActivity.this.sourceFile.exists())
          {
            if (!ListModeNewActivity.this.sourceFile.getName().toLowerCase().endsWith(".kmz"))
              break label146;
            if (FootprintUtils.isStorageEnough(ListModeNewActivity.this.getApplicationContext(), ListModeNewActivity.this.sourceFile.length()))
              ListModeNewActivity.this.advancedImportKMZ(ListModeNewActivity.this.sourceFile);
          }
          while (true)
          {
            ListModeNewActivity.this.dismissDialog(2);
            ListModeNewActivity.this.mFilter.filter(ListModeNewActivity.this.curCategory.mKeyword + "," + ListModeNewActivity.this.mSearchInput.getText() + "," + ListModeNewActivity.this.sortBy);
            return;
            label146: if (ListModeNewActivity.this.sourceFile.getName().toLowerCase().endsWith(".kml"))
            {
              if (!FootprintUtils.isStorageEnough(ListModeNewActivity.this.getApplicationContext()))
                continue;
              ListModeNewActivity.this.advancedImportKML(ListModeNewActivity.this.sourceFile);
              continue;
            }
            if ((!ListModeNewActivity.this.sourceFile.getName().toLowerCase().endsWith(".jpg")) || (!FootprintUtils.isStorageEnough(ListModeNewActivity.this.getApplicationContext())))
              continue;
            ListModeNewActivity.this.doPickPhotoAction(ListModeNewActivity.this.sourceFile);
          }
        }
      }
      .start();
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    requestWindowFeature(1);
    getWindow().setBackgroundDrawable(null);
    setContentView(2130903079);
    if (!StorageUtil.isInternalStorageEnough())
      showDialog(1);
    this.mPanelHost = getTabHost();
    SettingInfo localSettingInfo = SettingInfo.getInstance(this);
    if (localSettingInfo.isFirstLaunch())
    {
      showDialog(0);
      localSettingInfo.setFirstLaunch(false);
    }
    Intent localIntent = getIntent();
    this.mIsPicker = localIntent.getBooleanExtra("pick_footprint", false);
    this.dbManager = FootprintManager.getInstance(getApplicationContext());
    ArrayList localArrayList = this.dbManager.getAllCategory();
    localArrayList.add(0, Category.getAllCategory());
    this.sortBy = SettingInfo.getInstance(this).getSortString();
    Iterator localIterator = localArrayList.iterator();
    while (localIterator.hasNext())
    {
      Category localCategory3 = (Category)localIterator.next();
      TabSwitchHost localTabSwitchHost2 = this.mPanelHost;
      TabSwitchHost.TabSpec localTabSpec = this.mPanelHost.newTabSpec(localCategory3.mKeyword).setIndicator(localCategory3.mName, FootprintUtils.getTabCategoryIcon(getApplicationContext(), localCategory3.mKeyword), FootprintUtils.getInverseCategory(getApplicationContext(), localCategory3.mKeyword), FootprintUtils.getCategoryOverlayIcon(getApplicationContext(), localCategory3.mKeyword));
      1 local1 = new TabSwitchHost.TabContentFactory()
      {
        public View createTabContent(String paramString)
        {
          LayoutInflater localLayoutInflater = ListModeNewActivity.this.getLayoutInflater();
          if (ListModeNewActivity.this.listmode == null)
            ListModeNewActivity.access$002(ListModeNewActivity.this, localLayoutInflater.inflate(2130903063, null));
          if (ListModeNewActivity.this.listView == null)
          {
            ListModeNewActivity.access$102(ListModeNewActivity.this, (HtcListView)ListModeNewActivity.this.listmode.findViewById(16908298));
            if (!ListModeNewActivity.this.mIsPicker)
            {
              ListModeNewActivity.access$302(ListModeNewActivity.this, localLayoutInflater.inflate(2130903040, ListModeNewActivity.this.listView, false));
              ListModeNewActivity.this.mAddNewFootprintView.setTag(new SimpleSeparable());
              ListModeNewActivity.this.listView.addHeaderView(ListModeNewActivity.this.mAddNewFootprintView);
            }
            Cursor localCursor = ListModeNewActivity.this.dbManager.findFootprintCursorByCategory(null, ListModeNewActivity.this.sortBy);
            ListModeNewActivity.this.mAdapter = new ListModeNewActivity.ListModeAdapter(ListModeNewActivity.this, ListModeNewActivity.this.getApplicationContext(), 2130903062, localCursor);
            ListModeNewActivity.this.listView.setAdapter(ListModeNewActivity.this.mAdapter);
            ListModeNewActivity.this.listView.setClickable(true);
            ListModeNewActivity.this.listView.setOnItemClickListener(ListModeNewActivity.this.mAdapter);
            ListModeNewActivity.this.listView.setOnItemLongClickListener(ListModeNewActivity.this.mAdapter);
            ListModeNewActivity.this.listView.setRecyclerListener(ListModeNewActivity.this.mAdapter);
            ListModeNewActivity.this.listView.setFastScrollEnabled(true);
            ListModeNewActivity.access$602(ListModeNewActivity.this, ListModeNewActivity.this.mAdapter.getFilter());
          }
          return ListModeNewActivity.this.listmode;
        }

        final class SimpleSeparable
          implements HtcListItemSeparable
        {
          public SimpleSeparable()
          {
          }

          public boolean shouldDrawOnThis()
          {
            return true;
          }

          public boolean shouldSeparate(Object paramObject)
          {
            return true;
          }
        }
      };
      localTabSwitchHost2.addTab(localTabSpec.setContent(local1));
    }
    this.mPanelHost.setTabHintEnabled(true);
    TabSwitchHost localTabSwitchHost1 = this.mPanelHost;
    2 local2 = new TabSwitchHost.OnTabChangeSpecialListener()
    {
      public void onTabBeforeChange(String paramString)
      {
        ListModeNewActivity.this.mTitleView.setText("");
      }

      public void onTabChanged(String paramString)
      {
        if (paramString.equals(Category.getAllCategory().mKeyword))
          ListModeNewActivity.this.setCategory(Category.getAllCategory());
        while (true)
        {
          return;
          ListModeNewActivity.this.setCategory(ListModeNewActivity.this.dbManager.findCategory(paramString));
        }
      }
    };
    localTabSwitchHost1.setOnTabChangedListener(local2);
    this.mStorageUtil = new StorageUtil(getApplicationContext());
    StorageUtil localStorageUtil = this.mStorageUtil;
    3 local3 = new StorageUtil.OnChangeStorageListener()
    {
      public void onStorageChanged(int paramInt)
      {
        Intent localIntent;
        if (!StorageUtil.hasExternalStorage())
        {
          localIntent = new Intent("SDCardConfirmDialog");
          if (!StorageUtil.isMediaShared())
            break label50;
          localIntent.putExtra("DATA", ListModeNewActivity.this.getResources().getString(2131361955));
        }
        while (true)
        {
          ListModeNewActivity.this.startActivity(localIntent);
          return;
          label50: localIntent.putExtra("DATA", ListModeNewActivity.this.getResources().getString(2131361896));
        }
      }
    };
    localStorageUtil.SetOnChangeStorageListerner(local3);
    this.mTitleView = ((TextView)findViewById(2131492983));
    this.mSearchView = findViewById(2131492984);
    this.mSearchInput = ((TextView)findViewById(2131492985));
    this.mSearchInput.setInputType(112);
    TextView localTextView1 = this.mSearchInput;
    4 local4 = new TextWatcher()
    {
      public void afterTextChanged(Editable paramEditable)
      {
        ListModeNewActivity.this.mFilter.filter(ListModeNewActivity.this.curCategory.mKeyword + "," + ListModeNewActivity.this.mSearchInput.getText() + "," + ListModeNewActivity.this.sortBy);
      }

      public void beforeTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3)
      {
      }

      public void onTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3)
      {
      }
    };
    localTextView1.addTextChangedListener(local4);
    TextView localTextView2 = this.mSearchInput;
    5 local5 = new View.OnFocusChangeListener()
    {
      Handler handler = new Handler();
      private ResultReceiver receiver = new ResultReceiver(this.handler)
      {
        protected void onReceiveResult(int paramInt, Bundle paramBundle)
        {
        }
      };

      public void onFocusChange(View paramView, boolean paramBoolean)
      {
        InputMethodManager localInputMethodManager = (InputMethodManager)ListModeNewActivity.this.getSystemService("input_method");
        this.handler.postDelayed(new Runnable(paramBoolean, localInputMethodManager)
        {
          public void run()
          {
            if (this.val$hasFocus)
              this.val$imeManager.showSoftInput(ListModeNewActivity.this.mSearchInput, 1, ListModeNewActivity.5.this.receiver);
            while (true)
            {
              return;
              this.val$imeManager.focusIn(ListModeNewActivity.this.mSearchInput);
              this.val$imeManager.hideSoftInputFromWindow(ListModeNewActivity.this.mSearchInput.getWindowToken(), 1, ListModeNewActivity.5.this.receiver);
            }
          }
        }
        , 50L);
      }
    };
    localTextView2.setOnFocusChangeListener(local5);
    if (localIntent.getBooleanExtra("SEARCH", false))
      showSearch(true);
    View localView = findViewById(2131492986);
    6 local6 = new View.OnClickListener()
    {
      public void onClick(View paramView)
      {
        ListModeNewActivity.this.showSearch(false);
        ListModeNewActivity.this.mSearchInput.setText("");
      }
    };
    localView.setOnClickListener(local6);
    Category localCategory1 = (Category)localIntent.getParcelableExtra("CATEGORY");
    int i = localArrayList.indexOf(localCategory1);
    if (i < 0)
      i = 0;
    this.mPanelHost.setCurrentTab(i);
    if (localCategory1 == null);
    for (Category localCategory2 = Category.getAllCategory(); ; localCategory2 = localCategory1)
    {
      setCategory(localCategory2);
      bindLocationService();
      this.preloadRunnable = new PreloadDataRunnable(getApplicationContext(), null);
      PreloadDataRunnable localPreloadDataRunnable = this.preloadRunnable;
      7 local7 = new PreloadDataRunnable.PreloadListener()
      {
        public void preloadCompete(boolean paramBoolean)
        {
          ListModeNewActivity.access$1202(ListModeNewActivity.this, paramBoolean);
          Log.d("ListModeActivity", "Howard - mIsPreloadComplete:" + ListModeNewActivity.this.mIsPreloadComplete);
        }
      };
      localPreloadDataRunnable.setPreloadListener(local7);
      8 local8 = new Thread(this.preloadRunnable)
      {
      };
      local8.start();
      Log.d("ListModeActivity", "Howard - preloadRunnable start");
      return;
    }
  }

  protected Dialog onCreateDialog(int paramInt)
  {
    Object localObject;
    switch (paramInt)
    {
    default:
      localObject = super.onCreateDialog(paramInt);
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    case 7:
    }
    while (true)
    {
      return localObject;
      localObject = new HtcDialog(this).getWarningDialog();
      continue;
      localObject = new HtcDialog(this).getNoInternalStroageDialog();
      continue;
      HtcDialog.ImportDialog localImportDialog = new HtcDialog.ImportDialog(this);
      localImportDialog.setMessage(getString(2131361905));
      localImportDialog.setCancelable(false);
      localObject = localImportDialog;
      continue;
      if (this.sortBy.equals("create_time desc"));
      for (int i = 1; ; i = 0)
      {
        localObject = new HtcAlertDialog.Builder(this).setTitle(2131361890).setIcon(2130837677).setNegativeButton(2131361796, null).setSingleChoiceItems(2131165185, i, new DialogInterface.OnClickListener()
        {
          public void onClick(DialogInterface paramDialogInterface, int paramInt)
          {
            switch (paramInt)
            {
            default:
            case 0:
            case 1:
            }
            while (true)
            {
              ListModeNewActivity.this.mFilter.filter(ListModeNewActivity.this.curCategory.mKeyword + "," + ListModeNewActivity.this.mSearchInput.getText() + "," + ListModeNewActivity.this.sortBy);
              SettingInfo.getInstance(ListModeNewActivity.this).setSortString(ListModeNewActivity.this.sortBy);
              paramDialogInterface.dismiss();
              return;
              ListModeNewActivity.access$402(ListModeNewActivity.this, "name asc");
              ListModeNewActivity.access$1302(ListModeNewActivity.this, 0);
              continue;
              ListModeNewActivity.access$402(ListModeNewActivity.this, "create_time desc");
              ListModeNewActivity.access$1302(ListModeNewActivity.this, 1);
            }
          }
        }).create();
        break;
      }
      localObject = new HtcAlertDialog.Builder(this).setTitle(getString(2131361958)).setIcon(17301543).setMessage(getString(2131361870)).setNeutralButton(2131361893, null).create();
      continue;
      localObject = new HtcDialog(this).getPhotoPickerNotFoundDialog();
      continue;
      if (this.selectedFootprint != null)
      {
        HtcAlertDialog.Builder localBuilder = new HtcAlertDialog.Builder(this).setTitle(getString(2131361957)).setIcon(17301543);
        String str = getString(2131361816);
        Object[] arrayOfObject = new Object[1];
        arrayOfObject[0] = this.selectedFootprint.mName;
        localObject = localBuilder.setMessage(String.format(str, arrayOfObject)).setPositiveButton(2131361893, new DialogInterface.OnClickListener()
        {
          public void onClick(DialogInterface paramDialogInterface, int paramInt)
          {
            paramDialogInterface.dismiss();
            FootprintUtils.deleteFootprint(ListModeNewActivity.this.getApplicationContext(), ListModeNewActivity.this.selectedFootprint);
            new Handler().postDelayed(new Runnable()
            {
              public void run()
              {
                ListModeNewActivity.this.mAdapter.updateSections();
              }
            }
            , 300L);
          }
        }).setNegativeButton(2131361796, null).create();
        continue;
      }
      if (this.selectedFootprint == null)
        break;
      CharSequence[] arrayOfCharSequence = new CharSequence[4];
      arrayOfCharSequence[0] = getString(2131361807);
      arrayOfCharSequence[1] = getString(2131361808);
      arrayOfCharSequence[2] = getString(2131361825);
      arrayOfCharSequence[3] = getString(2131361972);
      localObject = new HtcAlertDialog.Builder(this).setTitle(this.selectedFootprint.mName).setIcon(2130837677).setItems(arrayOfCharSequence, new DialogInterface.OnClickListener()
      {
        public void onClick(DialogInterface paramDialogInterface, int paramInt)
        {
          paramDialogInterface.dismiss();
          switch (paramInt)
          {
          default:
          case 0:
          case 1:
          case 2:
          case 3:
          }
          while (true)
          {
            return;
            ListModeNewActivity.access$1502(ListModeNewActivity.this, true);
            Intent localIntent = new Intent("com.htc.android.footprints.activity.FootprintDetailEditActivity");
            try
            {
              localIntent.putExtra("DATA", ListModeNewActivity.this.selectedFootprint);
              ListModeNewActivity.this.startActivityForResult(localIntent, 400);
            }
            catch (Exception localException)
            {
              Log.e("ListModeActivity", "Disable to launch edit mode");
            }
            continue;
            ListModeNewActivity.this.showDialog(6);
            continue;
            Footprint[] arrayOfFootprint = new Footprint[1];
            arrayOfFootprint[0] = ListModeNewActivity.access$1400(ListModeNewActivity.this);
            FootprintUtils.exportKMZ(ListModeNewActivity.this, ListModeNewActivity.this.selectedFootprint.mName.replace(" ", "_"), arrayOfFootprint);
            continue;
            FootprintUtils.saveAsContacts(ListModeNewActivity.this.getApplicationContext(), ListModeNewActivity.this.selectedFootprint);
          }
        }
      }).create();
    }
  }

  public boolean onCreateOptionsMenu(Menu paramMenu)
  {
    paramMenu.add(0, 2, 2, getString(2131361961)).setIcon(2130837694);
    paramMenu.add(0, 0, 0, getString(2131361828)).setIcon(2130837687);
    paramMenu.add(0, 1, 1, getString(2131361829)).setIcon(2130837732);
    paramMenu.add(0, 3, 3, getString(2131361825)).setIcon(2130837680);
    paramMenu.add(0, 4, 4, getString(2131361845)).setIcon(2130837683);
    paramMenu.add(0, 5, 5, getString(2131361820)).setIcon(2130837678);
    paramMenu.add(0, 6, 6, getString(2131361949)).setIcon(2130837738);
    return true;
  }

  public void onDestroy()
  {
    super.onDestroy();
    FootprintImageManager.getInstance().clearCache("ListModeActivity");
    this.mPanelHost.clearAllTabs();
    this.mPanelHost.setOnTabChangedListener(null);
    ((ViewGroup)this.mPanelHost.getParent().getParent()).removeAllViews();
    this.mPanelHost = null;
    this.selectedFootprint = null;
    removeDialog(2);
    if (this.mAdapter != null)
      this.mAdapter.getCursor().close();
    this.listView.setAdapter(null);
    this.listView.getSelector().setCallback(null);
    this.listView.setOnItemClickListener(null);
    this.listView.setRecyclerListener(null);
    this.listView.setOnScrollListener(null);
    this.listView.getSelector().setCallback(null);
    this.listView.getBackground().setCallback(null);
    this.mSearchView.getBackground().setCallback(null);
    this.mSearchView.setBackgroundDrawable(null);
    this.mTitleView.getBackground().setCallback(null);
    this.mTitleView.setBackgroundDrawable(null);
    getLocalActivityManager().removeAllActivities();
    unbindLocationService();
  }

  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    if (paramInt == 84)
    {
      Intent localIntent = new Intent(this, SearchActivity.class);
      localIntent.putExtra("EXTRA_CATEGORY", this.curCategory.mKeyword);
      localIntent.putExtra("EXTRA_SORT_MODE", this.sortMode);
      localIntent.putExtra("EXTRA_CACHE_TAG", "ListModeActivity");
      startActivity(localIntent);
    }
    for (boolean bool = true; ; bool = super.onKeyDown(paramInt, paramKeyEvent))
      return bool;
  }

  public boolean onOptionsItemSelected(MenuItem paramMenuItem)
  {
    switch (paramMenuItem.getItemId())
    {
    default:
    case 0:
    case 1:
    case 4:
    case 3:
    case 6:
    case 2:
    case 5:
    case 7:
    }
    while (true)
    {
      for (int i = 1; ; i = 1)
      {
        while (true)
        {
          return i;
          Intent localIntent4 = new Intent("com.htc.android.footprints.activity.WrapShowOnMapActivity");
          localIntent4.putExtra("tab_index", this.mPanelHost.getCurrentTab());
          ArrayList localArrayList = new ArrayList();
          int j = this.listView.getFirstVisiblePosition();
          int k = this.listView.getLastVisiblePosition();
          if (!this.mIsPicker)
            k--;
          for (int m = j; m <= k; m++)
          {
            Footprint localFootprint = this.mAdapter.getFootprint(m);
            if (localFootprint.mAccuracy <= 0)
              continue;
            localArrayList.add(localFootprint);
          }
          localIntent4.putParcelableArrayListExtra("display", localArrayList);
          startActivity(localIntent4);
          break;
          showDialog(3);
          break;
          this.cursorMayBeDirty = true;
          Intent localIntent3 = new Intent();
          localIntent3.setClassName("com.htc.FilePicker", "com.htc.FilePicker.FilePicker");
          Bundle localBundle = new Bundle();
          localBundle.putString("application_name", getResources().getString(2131361795));
          localBundle.putString("title", getResources().getString(2131361845));
          String[] arrayOfString = new String[3];
          arrayOfString[0] = ".kmz";
          arrayOfString[1] = ".kml";
          arrayOfString[2] = ".jpg";
          localBundle.putStringArray("filter", arrayOfString);
          localIntent3.putExtras(localBundle);
          try
          {
            startActivityForResult(localIntent3, 10);
          }
          catch (ActivityNotFoundException localActivityNotFoundException)
          {
            showDialog(4);
          }
        }
        break;
        if (FootprintUtils.isStorageEnough(getApplicationContext(), 59300L * this.mAdapter.getCount()))
          break label360;
      }
      label360: if (this.mAdapter.getCount() <= 0)
        continue;
      Footprint[] arrayOfFootprint = this.mAdapter.getFootprints();
      if (this.curCategory == Category.getAllCategory());
      for (String str = "footprints"; ; str = this.curCategory.mName)
      {
        FootprintUtils.exportKMZ(this, str, arrayOfFootprint);
        break;
      }
      startActivity(new Intent("com.htc.android.footprints.activity.SettingActivity"));
      continue;
      startCameraActivity(true);
      continue;
      Intent localIntent2 = new Intent(this, DeleteFootprintsActivity.class);
      localIntent2.putExtra("EXTRA_CATEGORY", this.curCategory.mKeyword);
      localIntent2.putExtra("EXTRA_SORT_MODE", this.sortMode);
      localIntent2.putExtra("EXTRA_CACHE_TAG", "ListModeActivity");
      startActivity(localIntent2);
      continue;
      Intent localIntent1 = new Intent(this, SearchActivity.class);
      localIntent1.putExtra("EXTRA_CATEGORY", this.curCategory.mKeyword);
      localIntent1.putExtra("EXTRA_SORT_MODE", this.sortMode);
      localIntent1.putExtra("EXTRA_CACHE_TAG", "ListModeActivity");
      startActivity(localIntent1);
    }
  }

  protected void onPause()
  {
    super.onPause();
    if (this.mStorageUtil != null)
      this.mStorageUtil.closeStorgaeUtil();
  }

  public boolean onPrepareOptionsMenu(Menu paramMenu)
  {
    MenuItem localMenuItem4;
    if (this.mIsPicker)
    {
      paramMenu.getItem(0).setEnabled(false);
      paramMenu.getItem(3).setEnabled(false);
      paramMenu.getItem(5).setEnabled(false);
      paramMenu.getItem(6).setEnabled(false);
      paramMenu.getItem(4).setEnabled(false);
      paramMenu.getItem(2).setEnabled(false);
      localMenuItem4 = paramMenu.getItem(1);
      if (this.mAdapter.isEmpty())
        break label238;
    }
    label146: label176: label226: label232: label238: for (boolean bool4 = true; ; bool4 = false)
    {
      localMenuItem4.setEnabled(bool4);
      return true;
      MenuItem localMenuItem1 = paramMenu.getItem(0);
      boolean bool1;
      boolean bool2;
      MenuItem localMenuItem3;
      if (!this.mAdapter.isEmpty())
      {
        bool1 = true;
        localMenuItem1.setEnabled(bool1);
        MenuItem localMenuItem2 = paramMenu.getItem(3);
        if (this.mAdapter.isEmpty())
          break label226;
        bool2 = true;
        localMenuItem2.setEnabled(bool2);
        localMenuItem3 = paramMenu.getItem(5);
        if (this.mAdapter.isEmpty())
          break label232;
      }
      for (boolean bool3 = true; ; bool3 = false)
      {
        localMenuItem3.setEnabled(bool3);
        break;
        bool1 = false;
        break label146;
        bool2 = false;
        break label176;
      }
    }
  }

  protected void onResume()
  {
    super.onResume();
    Intent localIntent;
    if (!StorageUtil.hasExternalStorage())
    {
      localIntent = new Intent("SDCardConfirmDialog");
      if (!StorageUtil.isMediaShared())
        break label102;
      localIntent.putExtra("DATA", getResources().getString(2131361955));
    }
    while (true)
    {
      if (this.mService != null);
      try
      {
        this.mService.stopTrackingWithoutNotify();
        startActivity(localIntent);
        if (this.mStorageUtil != null)
          this.mStorageUtil.startStorageUtil();
        this.mAdapter.notifyDataSetChanged();
        if (this.cursorMayBeDirty)
          this.mAdapter.updateSections();
        return;
        label102: localIntent.putExtra("DATA", getResources().getString(2131361896));
      }
      catch (RemoteException localRemoteException)
      {
        while (true)
          localRemoteException.printStackTrace();
      }
    }
  }

  protected void onStart()
  {
    super.onStart();
  }

  protected void onStop()
  {
    super.onStop();
    if ((!this.mIsPreloadComplete) && (this.preloadRunnable != null))
      this.preloadRunnable.stopPreloading();
  }

  public void setCategory(Category paramCategory)
  {
    this.curCategory = paramCategory;
    this.mFilter.filter(paramCategory.mKeyword + "," + this.mSearchInput.getText() + "," + this.sortBy);
    if ((this.curCategory == null) || (this.curCategory.equals(Category.getAllCategory().mKeyword)))
      this.mTitleView.setText(getResources().getString(2131361880));
    while (true)
    {
      return;
      this.mTitleView.setText(this.curCategory.mName);
    }
  }

  void startCameraActivity(boolean paramBoolean)
  {
    Toast.makeText(this, getString(2131361963), 0).show();
    this.cursorMayBeDirty = true;
    Intent localIntent = new Intent(this, FootprintCamera.class);
    if (paramBoolean)
    {
      localIntent.putExtra("CATEGORY", this.curCategory);
      Log.i("ListModeActivity", "Selected category: " + this.curCategory.mName);
    }
    startActivity(localIntent);
  }

  public class ListModeAdapter extends ResourceCursorAdapter
    implements HtcAdapterView.OnItemClickListener, HtcAdapterView.OnItemLongClickListener, HtcAbsListView.RecyclerListener, SectionIndexer
  {
    private int columnIndexDate;
    private int columnIndexName;
    private int columnIndexTime;
    private boolean firstTime = true;
    FootprintImageManager imageManager = FootprintImageManager.getInstance();
    private String lastSectionString = "";
    private int positionIndex = 0;
    private Map<Integer, Integer> sectionIndex2PositionIndex = new HashMap();
    private ArrayList<String> sectionList = new ArrayList();
    SimpleDateFormat timeFormatter = new SimpleDateFormat("MM/dd/yy");

    ListModeAdapter(Context paramInt, int paramCursor, Cursor arg4)
    {
      super(paramCursor, localCursor);
      this.columnIndexTime = localCursor.getColumnIndexOrThrow("create_time");
      this.columnIndexName = localCursor.getColumnIndexOrThrow("name");
      this.columnIndexDate = localCursor.getColumnIndexOrThrow("short_date");
    }

    private Intent createReturnIntent(int paramInt)
    {
      Footprint localFootprint = getFootprint(paramInt);
      double d1 = localFootprint.mLatitude / 1000000.0D;
      double d2 = localFootprint.mLongitude / 1000000.0D;
      Intent localIntent = new Intent();
      localIntent.putExtra("RETURN_LATITUDE", d1);
      localIntent.putExtra("RETURN_LONGITUDE", d2);
      localIntent.putExtra("RETURN_LATITUDE_TEXT", String.valueOf(d1));
      localIntent.putExtra("RETURN_LONGITUDE_TEXT", String.valueOf(d2));
      return localIntent;
    }

    private void updateSections(Cursor paramCursor)
    {
      ListModeNewActivity.this.listView.setFastScrollSectionsDirty();
      this.lastSectionString = "";
      this.positionIndex = 0;
      this.sectionList.clear();
      this.sectionIndex2PositionIndex.clear();
      this.firstTime = true;
      if (paramCursor != null)
      {
        if (ListModeNewActivity.this.sortMode == 1)
          while (paramCursor.moveToPosition(this.positionIndex))
          {
            String str4 = paramCursor.getString(this.columnIndexDate);
            if (TextUtils.isEmpty(str4))
            {
              long l = paramCursor.getLong(this.columnIndexTime);
              str4 = this.timeFormatter.format(new Date(l));
            }
            if (!str4.equals(this.lastSectionString))
            {
              this.lastSectionString = str4;
              this.sectionIndex2PositionIndex.put(Integer.valueOf(this.sectionList.size()), Integer.valueOf(this.positionIndex));
              this.sectionList.add(str4);
            }
            this.positionIndex = (1 + this.positionIndex);
          }
        if (paramCursor.moveToPosition(this.positionIndex))
        {
          String str1 = paramCursor.getString(this.columnIndexName);
          if (!TextUtils.isEmpty(str1))
          {
            if (this.firstTime)
              break label301;
            if (!str1.startsWith(this.lastSectionString))
            {
              String str3 = str1.substring(0, 1);
              this.lastSectionString = str3;
              this.sectionIndex2PositionIndex.put(Integer.valueOf(this.sectionList.size()), Integer.valueOf(this.positionIndex));
              this.sectionList.add(str3);
            }
          }
          while (true)
          {
            this.positionIndex = (1 + this.positionIndex);
            break;
            label301: this.firstTime = false;
            String str2 = str1.substring(0, 1);
            this.lastSectionString = str2;
            this.sectionIndex2PositionIndex.put(Integer.valueOf(0), Integer.valueOf(0));
            this.sectionList.add(str2);
          }
        }
      }
    }

    public void bindView(View paramView, Context paramContext, Cursor paramCursor)
    {
      ItemViewHolder localItemViewHolder = (ItemViewHolder)paramView.getTag();
      Footprint localFootprint = new Footprint();
      FootprintManager.fillDataFromCursor(localFootprint, paramCursor);
      Drawable localDrawable;
      if ((localItemViewHolder.iconView.getWidth() == 0) || (localItemViewHolder.iconView.getHeight() == 0))
      {
        ViewGroup.LayoutParams localLayoutParams = localItemViewHolder.iconView.getLayoutParams();
        localDrawable = this.imageManager.getScaledFastImage("ListModeActivity", localFootprint.mPicPath, localLayoutParams.width, localLayoutParams.height);
        localItemViewHolder.iconView.setImageDrawable(localDrawable);
        if (TextUtils.isEmpty(localFootprint.mShortDate))
          break label327;
        localItemViewHolder.time.setText(localFootprint.mShortDate);
      }
      int i;
      String str1;
      SpannableString localSpannableString2;
      while (true)
      {
        CharSequence localCharSequence = ListModeNewActivity.this.mSearchInput.getText();
        i = localCharSequence.length();
        str1 = localCharSequence.toString().toLowerCase();
        if (localFootprint.mName == null)
          break label528;
        if (i <= 0)
          break label512;
        String str4 = localFootprint.mName.toLowerCase();
        localSpannableString2 = new SpannableString(localFootprint.mName);
        if (str4.startsWith(str1))
          localSpannableString2.setSpan(new BackgroundColorSpan(-29421), 0, i, 33);
        int k = -1;
        String str5 = " " + str1;
        while (true)
        {
          k = str4.indexOf(str5, k + 1);
          if (k <= -1)
            break;
          localSpannableString2.setSpan(new BackgroundColorSpan(-29421), k + 1, 1 + (i + k), 33);
        }
        localDrawable = this.imageManager.getScaledFastImage("ListModeActivity", localFootprint.mPicPath, localItemViewHolder.iconView.getWidth(), localItemViewHolder.iconView.getHeight());
        break;
        label327: localItemViewHolder.time.setText(this.timeFormatter.format(new Date(localFootprint.mCreateTime)));
      }
      localItemViewHolder.title.setText(localSpannableString2);
      while (true)
      {
        if (localFootprint.mAddr == null)
          break label568;
        if (i <= 0)
          break;
        String str2 = localFootprint.mAddr.toLowerCase();
        SpannableString localSpannableString1 = new SpannableString(localFootprint.mAddr);
        if (str2.startsWith(str1))
          localSpannableString1.setSpan(new BackgroundColorSpan(-29421), 0, i, 33);
        int j = -1;
        String str3 = " " + str1;
        while (true)
        {
          j = str2.indexOf(str3, j + 1);
          if (j > -1)
          {
            localSpannableString1.setSpan(new BackgroundColorSpan(-29421), j + 1, 1 + (i + j), 33);
            continue;
            label512: localItemViewHolder.title.setText(localFootprint.mName);
            break;
            label528: localItemViewHolder.title.setText("");
            break;
          }
        }
        localItemViewHolder.address.setText(localSpannableString1);
      }
      while (true)
      {
        return;
        localItemViewHolder.address.setText(localFootprint.mAddr);
        continue;
        label568: localItemViewHolder.address.setText("");
      }
    }

    public void changeCursor(Cursor paramCursor)
    {
      updateSections(paramCursor);
      super.changeCursor(paramCursor);
    }

    public Footprint getFootprint(int paramInt)
    {
      Footprint localFootprint1;
      if ((Cursor)getItem(paramInt) != null)
      {
        localFootprint1 = new Footprint();
        FootprintManager.fillDataFromCursor(localFootprint1, getCursor());
      }
      for (Footprint localFootprint2 = localFootprint1; ; localFootprint2 = null)
        return localFootprint2;
    }

    public Footprint[] getFootprints()
    {
      Footprint[] arrayOfFootprint = new Footprint[getCount()];
      for (int i = 0; i < arrayOfFootprint.length; i++)
        arrayOfFootprint[i] = getFootprint(i);
      return arrayOfFootprint;
    }

    public int getPositionForSection(int paramInt)
    {
      try
      {
        int j = ((Integer)this.sectionIndex2PositionIndex.get(Integer.valueOf(paramInt))).intValue();
        i = j;
        return i;
      }
      catch (Exception localException)
      {
        while (true)
        {
          Log.e("ListModeActivity", "getPositionForSection() error: " + paramInt);
          int i = 0;
        }
      }
    }

    public int getSectionForPosition(int paramInt)
    {
      return 0;
    }

    public Object[] getSections()
    {
      Object localObject;
      if (this.sectionList.size() > 0)
        localObject = this.sectionList.toArray();
      while (true)
      {
        return localObject;
        localObject = new String[1];
        localObject[0] = " ";
      }
    }

    public View newView(Context paramContext, Cursor paramCursor, ViewGroup paramViewGroup)
    {
      View localView = super.newView(paramContext, paramCursor, paramViewGroup);
      ItemViewHolder localItemViewHolder = new ItemViewHolder(null);
      localItemViewHolder.iconView = ((ImageView)localView.findViewById(2131492899));
      localItemViewHolder.title = ((TextView)localView.findViewById(2131492900));
      localItemViewHolder.address = ((TextView)localView.findViewById(2131492901));
      localItemViewHolder.time = ((TextView)localView.findViewById(2131492902));
      localView.setTag(localItemViewHolder);
      return localView;
    }

    public void onItemClick(HtcAdapterView<?> paramHtcAdapterView, View paramView, int paramInt, long paramLong)
    {
      if (ListModeNewActivity.this.mIsPicker)
      {
        ListModeNewActivity.this.setResult(-1, createReturnIntent(paramInt));
        ListModeNewActivity.this.finish();
      }
      while (true)
      {
        return;
        if (paramInt != 0)
        {
          int i = paramInt - 1;
          Intent localIntent = new Intent("com.htc.android.footprints.activity.DetailViewActivity");
          localIntent.putExtra("DATA", getFootprint(i));
          localIntent.putExtra("EXTRA_SORT_BY", ListModeNewActivity.this.sortBy);
          localIntent.putExtra("EXTRA_CATEGORY", ListModeNewActivity.this.curCategory.mKeyword);
          localIntent.putExtra("EXTRA_ITEM_IDX", i);
          ListModeNewActivity.this.startActivity(localIntent);
          continue;
        }
        ListModeNewActivity.this.startCameraActivity(true);
      }
    }

    public boolean onItemLongClick(HtcAdapterView<?> paramHtcAdapterView, View paramView, int paramInt, long paramLong)
    {
      if ((!ListModeNewActivity.this.mIsPicker) && (paramInt != 0))
      {
        int i = paramInt - 1;
        ListModeNewActivity.access$1402(ListModeNewActivity.this, getFootprint(i));
        ListModeNewActivity.this.showDialog(7);
      }
      return true;
    }

    public void onMovedToScrapHeap(View paramView)
    {
      ((ItemViewHolder)paramView.getTag()).iconView.setImageDrawable(null);
    }

    public Cursor runQueryOnBackgroundThread(CharSequence paramCharSequence)
    {
      Cursor localCursor;
      if (getFilterQueryProvider() != null)
      {
        localCursor = getFilterQueryProvider().runQuery(paramCharSequence);
        return localCursor;
      }
      if (paramCharSequence == null)
        paramCharSequence = "";
      String[] arrayOfString = paramCharSequence.toString().split(",");
      String str1 = "";
      String str2 = "";
      String str3;
      if (arrayOfString.length == 1)
        str3 = arrayOfString[0];
      while (true)
      {
        localCursor = ListModeNewActivity.this.dbManager.getCursorSortBy(str3, str1, str2);
        break;
        if (arrayOfString.length == 2)
        {
          str3 = arrayOfString[0];
          str1 = arrayOfString[1];
          continue;
        }
        str3 = arrayOfString[0];
        str1 = arrayOfString[1];
        str2 = arrayOfString[2];
      }
    }

    public void updateSections()
    {
      updateSections(getCursor());
    }

    private class ItemViewHolder
      implements HtcListItemSeparable
    {
      TextView address;
      ImageView iconView;
      Runnable runnable;
      TextView time;
      TextView title;

      private ItemViewHolder()
      {
      }

      public boolean shouldDrawOnThis()
      {
        return true;
      }

      public boolean shouldSeparate(Object paramObject)
      {
        return false;
      }
    }
  }
}

/* Location:           E:\workspace\dex2java\dex-translator-0.0.9.3\HtcFootprints_dex2jar.jar
 * Qualified Name:     com.htc.android.footprints.activity.ListModeNewActivity
 * JD-Core Version:    0.6.0
 */